package com.kedacom.demo.redis.springdataredis.script;

import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.core.script.RedisScript;

/**
 * SpringDataRedisScripts
 * @author luocanfeng
 * @date 2015年9月8日
 */
public class SpringDataRedisScripts {

	public static final RedisScript<Boolean> check_and_set_script;
	public static final RedisScript<String> test_cjson_script;
	public static final RedisScript<String> test_function_script;

	static {
		check_and_set_script = getScript("lua/checkAndSet.lua", Boolean.class);
		test_cjson_script = getScript("lua/test_cjson.lua", String.class);
		test_function_script = getScript("lua/test_function.lua", String.class);
	}

	public static <T> RedisScript<T> getScript(String scriptLocation, Class<T> resultType) {
		DefaultRedisScript<T> redisScript = new DefaultRedisScript<T>();
		redisScript.setLocation(new ClassPathResource(scriptLocation));
		redisScript.setResultType(resultType);
		return redisScript;
	}

}
